package cn.ichiva.dl.tushare.tu.data.daily;

import cn.ichiva.tushare.sdk.tushare.TuConfig;
import cn.ichiva.tushare.sdk.tushare.entity.TuTable;
import cn.ichiva.dl.tushare.tu.data.Shibor;
import cn.ichiva.dl.tushare.tu.data.TradeCal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShiborDailyData implements DailyData {

    Map<String,String[]> map = new HashMap<>();

    public ShiborDailyData(TuConfig config){
        TuTable tuTable = new Shibor(config).get().get();
        DailyData.smooth(tuTable);
        for (String[] item : tuTable.getItems()) {
            map.put(item[0],item);
        }

        List<String> cal = new TradeCal(config).getTradingDay();
        //日期平滑
        String first = cal.get(cal.size() - 1);
        String[] pro = map.get(first);
        for (int i = cal.size() - 2; i >= 0; i--) {
            String date = cal.get(i);
            String[] data = map.get(date);
            if(data == null) map.put(date,pro);
            else pro = data;
        }
    }

    @Override
    public String[] findByDaily(String day) {
        return map.get(day);
    }
}
